package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/tologin")
    public String tologin(){
        return "login";
    }
    @RequestMapping("/toadd")
    public String toadd(){
        return "register";
    }

    @RequestMapping("/add")
    public String add(User user){
        user.setDate(new Date());
        roleService.add(user);
        return "redirect:tologin";
    }


    @RequestMapping("/login")
    public String login(User user){
       User num = roleService.findUser(user);
       if (num==null){
           return "login";
       }
       String rold = roleService.findRidByUid(num.getId());
       if (rold.equals("管理员")){
           return "redirect:/etc/guan";
       }else {
           return "redirect:/etc/show";
       }

    }
}
